<template>
<div>
    <TopFilter
      :list="topFilterList"
      :cols="4"
      @filterChange="changeHandle"
    ></TopFilter>
    <FilterTable
      ref="table"
      columnsRef="dealerList"
      :columns="columns"
      :fetchapi="fetchApi"
      selectionType='single'
      :params="fetchParams"
      :datakey="'rows'"
      :onColumnsChange="columns => {this.columns = columns}"
      :onRowSelectChange='saveData'
    >
    </FilterTable>
    <div>
        <el-button size="mini" type="text" @click="choose">确定</el-button>
        <el-button size="mini" type="text" >取消</el-button>
    </div>
</div>
</template>
<script>
    //  import { dealersSelect } from '@/api/part/partInfoManage/contactsCustomer';
    export default{
        data(){
            this.BaseTable = null;
            this.tableData = null;
            return {
                topFilterList: this.createTopList(),
                columns:this.createColumns(),
                // fetchApi: dealersSelect,
                fetchApi: '',
                fetchParams: {},
                data: []
            }
        },
        methods:{
            createTopList(){
                return [
                    {
                        type: 'SELECT',
                        label: '品牌',
                        fieldName: 'brandCode',
                        placeholder: '请选择',
                        itemList: [{value:'0',text:'卡迪拉克'},{value:'1',text:'宝马'},
                        {value:'2',text:'林肯'},{value:'3',text:'其他'}]
                    }
                ]
            },
            createColumns(){
                return [
                    {
                        title: '序号',
                        dataIndex: 'index1',
                        width: 70,
                        fixed: 'left',
                        sorter: true,
                        render: (props,h) => {
                            return <span> {props.row.index + 1} </span>;
                        }
                    },
                    {
                        title: '经销商代码',
                        dataIndex: 'dealerCode',
                        filterType: 'input'
                    },
                    {
                        title: '经销商简称',
                        dataIndex: 'DEALER_SHORT_NAME',
                        filterType: 'input'
                    },
                    {
                        title: '经销商全称',
                        dataIndex: 'dealerFullName',
                        filterType: 'input'
                    },
                    {
                        title: '品牌',
                        dataIndex: 'brandCode',
                        filterType: 'input'
                    }
                ]
            },
            async changeHandle(val){
                console.log(val);
                this.fetchParams=Object.assign({},this.fetchParams, val);
            },
            choose(){
                let res = Object.assign({}, this.tableData);
                console.log(res);
                this.$emit('reAdd', 0, res);
            },
            saveData(row){
                console.log(row);
                this.tableData = row[0];
            }
        },
        mounted(){
            this.BaseTable = this.$refs.table.$refs.pageTable;
        }
    }
</script>
<style>
</style>
